#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "list.h"

extern char *s_gets(char *st,int n);
void showmovies(Item item);

int main(void)
{

	List movies;
	Item temp;
	InitializeList(&movies);
	if(ListIsFull(&movies))
	{
		fprintf(stderr,"No memory availvale\n");
		exit(1);
	}

	puts("Enter first movie titel");
	while(s_gets(temp.title,TSIZE) != NULL && temp.title[0] != '\0')
	{
		puts("Enter your rating<0 - 10>");
		scanf("%d",&temp.rating);
		while(getchar() != '\n')
		{
			continue;
		}
		if(!AddItem(temp,&movies))
		{
			fprintf(stderr,"Problem allocating memory\n");
			break;
		}
		if(ListIsFull(&movies))
		{
			puts("The list is full");
			break;
		}
		puts("Enter next movie title (empty line to stop!)");
	}
	if(ListIsEmpty(&movies))
	{
		printf("No data entered!");
	}
	else
	{
		printf("Here is the movie list:\n");
		Traverse(&movies,showmovies);
	}
	printf("You entered %d movies.\n",ListItemCount(&movies));
	EmptyTheList(&movies);
	puts("Byes!\n");
	return EXIT_SUCCESS;
}

void showmovies(Item item)
{
	printf("Movie: %s Rating: %d \n",item.title,item.rating);
}
